package oop;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Improme {
    //属性
    boolean bool=true;
    String details="--------------零钱通明细---------";
    //定义变量
    double money=0;//收益
    double balance=0;//余额
    String note=null;//消费原因
    String exit="";
    //创建类对象
    Date date=null;
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm");
    Scanner scanner =new Scanner(System.in);

    //方法
    public void menu(){
        System.out.println("========零钱通菜单==========");
        System.out.println("\t\t\t1 零钱通明细");
        System.out.println("\t\t\t2 收益入账");
        System.out.println("\t\t\t3 消费");
        System.out.println("\t\t\t4 退出");
        System.out.println("请选择1~4:");
    }
    public void chargemenu(){
        System.out.println(details);
    }
    //2.收入
    public void income(){
        System.out.println("收益入账");
        money= scanner.nextDouble();
        //判断金额
        if(money<=0){
            System.out.println("收益入账应大于0");
            return;
        }
        balance+=money;
        date =new Date();
        details+="\n收益入账 \t+"+money+"\t"+sdf.format(date)+"\t"+balance;
    }
    //3.消费
    public void consume(){
        System.out.println("消费金额");
        money= scanner.nextDouble();
        //消费金额判断
        if(money>balance||money<=0){
            System.out.println("消费金额应在0~"+balance);
           return;
        }
        System.out.println("消费原因");
        note= scanner.next();
        balance-=money;
        date =new Date();
        details+="\n"+note+" \t-"+money+"\t"+sdf.format(date)+"\t"+balance;
    }
    //4.退出
    public void exit(){
        System.out.println("退出");
        System.out.println("确认要退出吗?  请选择y/n");
        while(true){
            exit= scanner.next();
            if(exit.equals("y")||exit.equals("n")){
                break;
            }
            else{
                System.out.println("输入错误,请选择y/n");
            }
        }
        if(exit.equals("y")){
            bool=false;
        }
    }

}

